<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="myUtil.productCheck" %>
<%@ page import="java.sql.*" %>
<html>
<head>
    <title>product_save</title>
</head>
<body>
<%
    String I = request.getParameter("id");
    int i = Integer.parseInt(I);
    String productCode = request.getParameter("productCode");
    String productName = request.getParameter("productName");
    String productSize = request.getParameter("productSize");
    String batch = request.getParameter("batch");
    String worker = request.getParameter("worker");
    String processingMethod = request.getParameter("processingMethod");
    String processingDate = request.getParameter("processingDate");
    String workshop = request.getParameter("workshop");
    String instructionNumber = request.getParameter("instructionNumber");
    String instructionContent = request.getParameter("instructionContent");
    if (productCheck.checkCode(productCode) && productCheck.checkS(productName) && productCheck.checkS(productSize) &&
            productCheck.checkBatch(batch) && productCheck.checkS(worker) && productCheck.checkS(processingMethod) &&
            productCheck.checkS(processingDate) &&productCheck.checkS(workshop)) {
        Connection conn = (Connection)session.getAttribute("Connection");
        String sql = "UPDATE product SET productCode = ?, productName = ?, productSize = ?, batch = ?, worker = ?, processingMethod = ?, processingDate = ?, workshop = ? WHERE id = "+i;
        PreparedStatement preparedStatement = conn.prepareStatement(sql);
        preparedStatement.setString(1, productCode);
        preparedStatement.setString(2, productName);
        preparedStatement.setString(3, productSize);
        preparedStatement.setString(4, batch);
        preparedStatement.setString(5, worker);
        preparedStatement.setString(6, processingMethod);
        preparedStatement.setString(7, processingDate);
        preparedStatement.setString(8, workshop);

        int rowsUpdated = preparedStatement.executeUpdate();
        if (rowsUpdated > 0) {

        } else {

        }

        response.sendRedirect("product_list.jsp");
    } else {
        request.getRequestDispatcher("product_add.jsp").forward(request, response);
    }

%>
</body>
</html>
